<!DOCTYPE HTML>
<html>
<head>
  <title>Error</title>
  <link rel="stylesheet" href="/stylesheets/style.css">
  <script src="/scripts/jquery.min.js"></script>
  <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
  <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
  <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
<div style="margin: 0 auto;text-align: center">
  <span style="width:60px;display:inline-block;">部落名称：</span>
  <input id="name" class="mini-textbox" style="width:155px;" value='<%= result.data[0].name %>' type="text"/>
  <span style="width:60px;display:inline-block; margin-left: 20px">部落分类：</span>
  <input id="category" class="mini-combobox" style="width:155px;" data="tribeCategory" value='<%= result.data[0].category %>' type="text"/>
  <br/><br/>

  <span style="width:60px;display:inline-block;">部落号码：</span>
  <input id="num" class="mini-textbox" style="width:155px;" value='<%= result.data[0].num %>' readonly="true" type="number"/>
  <span style="width:60px;display:inline-block; margin-left: 20px">帖子数量：</span>
  <input id="postNum" class="mini-textbox" style="width:155px;" value='<%= result.data[0].postNum %>' type="number"/>
  <br/><br/>

  <span style="width:60px;display:inline-block;">部落规模：</span>
  <input id="capacity" class="mini-textbox" style="width:155px;" value='<%= result.data[0].capacity %>' type="number"/>
  <span style="width:60px;display:inline-block; margin-left: 20px">成员数量：</span>
  <input id="memberNum" class="mini-textbox" style="width:155px;" value='<%= result.data[0].memberNum %>' type="number"/>
  <br/><br/>

  <span style="width:60px;display:inline-block;">是否公开：</span>
  <input id="isPublic" class="mini-combobox" style="width:155px;" data="tribeIsPublic" value='<%= result.data[0].isPublic %>' type="text"/>
  <span style="width:60px;display:inline-block; margin-left: 20px">部落状态：</span>
  <input id="status" class="mini-combobox" style="width:155px;" data="tribeStatus" value='<%= result.data[0].status %>' type="text"/>
  <br/><br/>

  <span style="width:60px;display:inline-block;">认证方式：</span>
  <input id="verify" class="mini-combobox" style="width:155px;" onvaluechanged="verifyValueChanged" data="tribeVerify" value='<%= result.data[0].verify %>' type="number" />
  <span style="width:60px;display:inline-block; margin-left: 20px">付费金额：</span>
  <input id="verifyCost" class="mini-textbox" style="width:155px;"  value='<%= result.data[0].verifyCost %>' type="number" />
  <br/><br/>

  <span style="width:60px;display:inline-block;">推广分成：</span>
  <input id="generalize" class="mini-combobox" style="width:155px;" data="tribeGeneralize" value='<%= result.data[0].generalize %>' type="number"/>
  <span style="width:60px;display:inline-block; margin-left: 20px">排序编号：</span>
  <input id="sortDate" class="mini-textbox" style="width:155px;" value='<%= result.data[0].sortDate %>' type="number"/>
  <br/><br/>

  <span style="width:60px;display:inline-block;">部落公告：</span>
  <textarea id="introduction" class="mini-textarea"  value="<%= result.data[0].introduction%>" style="width: 400px;height: 100px"></textarea>
  <br/><br/>
</div>
<div style="margin: 0 auto;text-align: center">
  <a class="mini-button " iconCls="icon-ok" onclick="updateTribeInfo()">确定</a>
  <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
</div>
</body>
<script>
  var tribeCategory = JSON.parse('<%- result.tribeCategory %>');
  var tribeStatus = [{ id: -1, text: '删除' }, { id: 0, text: '锁定'},{ id: 1, text: '正常'}];
  var tribeIsPublic = [{ id: 0, text: '私有' }, { id: 1, text: '公开'}];
  var tribeVerify = [{ id: 1, text: '无需验证' }, { id: 2, text: '需要验证'},{ id: 3, text: '付费加入'},{ id: 4, text: '禁止加入'}];
  var tribeGeneralize = [{ id: 0, text: '关闭' }, { id: 1 ,text: '开启'}];
  var objectId = '<%= result.data[0].objectId%>';
  function verifyValueChanged(e) {
    var verfyCostObj = mini.get("verifyCost");
    if (e.value !=3 ) {
      verfyCostObj.setValue(undefined);
      verfyCostObj.allowInput = false;
    } else {
      verfyCostObj.allowInput = true;
    }
  }
  function updateTribeInfo() {

    var name = mini.get("name").getValue();
    if (!showError(name,'部落名称不能为空')){
        return;
    };
    var category = mini.get("category").getText();
    if (!showError(category,'部落分类不能为空')){
      return;
    };
    var postNum = mini.get("postNum").getValue();
    if (!showError(postNum,'帖子数量不能为空')){
      return;
    };
    var capacity = mini.get("capacity").getValue();
    if (!showError(capacity,'部落规模不能为空')){
      return;
    };
    var memberNum = mini.get("memberNum").getValue();
    if (!showError(memberNum,'部落成员不能为空')){
      return;
    };
    if (memberNum < 1) {
      alert('部落成员需大于1');
      return;
    }
    var isPublic = mini.get("isPublic").getValue();
    if (!showError(isPublic,'是否公开不能为空')){
      return;
    };
    var status = mini.get("status").getValue();
    if (!showError(status,'部落状态不能为空')){
      return;
    };
    var verify = mini.get("verify").getValue();
    if (!showError(verify,'部落认证不能为空')){
      return;
    };
    var verifyCost;
    if (verify == 3) {
      verifyCost = mini.get("verifyCost").getValue();
      if (!showError(verifyCost,'请输入付费金额')){
        return;
      };
    } else {
      verifyCost = undefined;
    }

    var generalize = mini.get("generalize").getValue();
    if (!showError(generalize,'推广分成不能为空')){
      return;
    };
    var sortDate = mini.get("sortDate").getValue();
    if (!showError(sortDate,'排序编号不能为空')){
      return;
    };
    var introduction = mini.get("introduction").getValue();
    $.ajax({
      type: "POST",
      url: "/tribeRoute/updateTribeInfo",
      data: {
        objectId: objectId,
        name: name,
        category: category,
        postNum: postNum,
        capacity: capacity,
        memberNum:memberNum,
        isPublic: isPublic,
        status: status,
        verify: verify,
        verifyCost: verifyCost,
        generalize: generalize,
        sortDate:sortDate,
        introduction:introduction,
      },
      success: function (result) {
        CloseWindow("save");
      }
    })
  }
  function showError(val,text) {
    if (val=="" || val==undefined || val==null){
      alert(text);
      return false;
    } else {
      return true;
    }
  }
  //    关闭窗口
  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }
  function onOk(e) {
    SaveData();
  }
  function onCancel(e) {
    CloseWindow("cancel");
  }

</script>
</html>